<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/nfwt.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue3 + CDN </title>
    <script type="text/javascript">
      // 假定 src在网站根目录
      let basrUrl = '/' 
      // 判断所处网站，确定基础url
      switch (window.location.origin) {
        case 'https://naturefwvue.github.io': //github
        case 'https://naturefw-project.gitee.io': //gitee
          basrUrl = '/vue3-cnd/'
          break
      }

      // 判断是否刷新的情况
      const url = window.location.href
      const paths = url.split('/')

      // 查找标记
      const flag = {
        kind: '',
        url: '',
        index: 0
      }

      paths.forEach((item, index) => {
        if (item.includes('cdn')){
          flag.index = index
          flag.kind = item
          flag.url = url.replace(paths.splice(0, index + 1 ).join('/'), '').replace('/','')
        }
      })

      console.log(flag)
      if (flag.kind) {
        // 跳回去
        window.location.href = `${basrUrl}${flag.kind}?url=${flag.url}` // 
      }

    </script>
  </head>
  <body>
    <div id="app">
      <a href="cdn1" >简单的演示</a> <br>
      <br>
      <a href="cdn2" >import的方式</a> <br>
      <br>
      <a href="cdn3" >仿工程化</a> <br>
      <br>
      <a href="cdn4" >二次封装</a> <br>
     
    </div>
  </body>
</html>
